package com.mabs.ground.client.module.connexion.activity;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.mabs.ground.client.common.ClientFactory;
import com.mabs.ground.client.common.MyAbstractActivity;
import com.mabs.ground.client.module.connexion.place.ConnexionPlace;
import com.mabs.ground.client.module.connexion.view.ConnexionView;
import com.mabs.ground.shared.DataResponseBean;
import com.mabs.ground.shared.UserBean;

/**
 * @author <a href="Email: mohamedarbi.benslimane@allence-tunisie.com">Ben
 *         Slimane Arbi</a>
 * @version 1.0
 * @since 1.0 - 25 juil. 2014 - 19:35:42
 */
public class ConnexionActivity extends MyAbstractActivity {

	public ConnexionActivity(ConnexionPlace place, ClientFactory clientFactory) {
		super(clientFactory);
		display = getClientFactory().getConnexionView();
	}

	private ConnexionView display;

	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
		getClientFactory().getMain().setMainPanel(display.asWidget());
		display.getValiderClickHandlers().addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {

				// using DataREsponse userBean
				Class<DataResponseBean<UserBean>> ur = getClientFactory()
						.getMyBeanFactory().userResponse().getType();
				requestData("/rest/user/11", null,
						new MyRequestCallback<UserBean>(ur) {

							@Override
							public void onResponseReceivedDo(
									DataResponseBean<UserBean> m) {
								Window.alert("New version : user id recieved :"
										+ m.getTotalRows());
							}

						});
			}
		});
	}
}
